import regeneratorRuntime from '../../../resource/libs/runtime'
import service from '../../../common/service'

Page({
  data: {
    feedback: '',
    feedback_num: 0,
    loading: false
  },

  feedbackInput ({ detail }) {
    let value = detail.value
    this.setData({
      feedback: value,
      feedback_num: value.length
    })
  },

  async submit () {
    if (this.data.loading) { return }
    this.setData({ loading: true })
    let remark = this.data.feedback
    let res = await service.postPromise('message/save', { remark })
    this.setData({ loading: false })
    if (!res) { return }
    if (typeof res === 'number') {
      wx.showModal({
        title: '提交失败',
        showCancel: false
      })
      return
    }
    wx.showToast({
      title: '留言成功',
      icon: 'success'
    })
    let t = setTimeout(() => {
      clearTimeout(t)
      wx.navigateBack({
        delta: 1
      })
    }, 500)
  }
})